package sample;

import javafx.event.Event;
import javafx.fxml.FXML;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.stage.FileChooser;

import java.io.File;

public class Controller {
    //第1行 选择框 输入框
    @FXML
    private CheckBox checkBox1;
    @FXML
    private TextField field11;
    @FXML
    private TextField field12;
    //第2行  输入框
    @FXML
    private CheckBox checkBox2;
    @FXML
    private TextField field21;
    @FXML
    private TextField field22;
    //第3行  输入框
    @FXML
    private CheckBox checkBox3;
    @FXML
    private TextField field31;
    @FXML
    private TextField field32;
    @FXML
    private TextField field33;
    //第4行  输入框
    @FXML
    private CheckBox checkBox4;
    @FXML
    private TextField field41;
    @FXML
    private TextField field42;
    @FXML
    private TextField field43;
    //第5行  输入框
    @FXML
    private CheckBox checkBox5;
    @FXML
    private TextField field51;
    @FXML
    private TextField field52;
    @FXML
    private TextField field53;
    //第6行  输入框
    @FXML
    private CheckBox checkBox6;
    @FXML
    private TextField field61;
    @FXML
    private TextField field62;
    @FXML
    private TextField field63;


    @FXML
    private Label fileLabel;
    //文件选择器
    final FileChooser fileChooser = new FileChooser();

    @FXML
    public void exeButClickedHandle(Event event) {

        if (this.checkBox1.isSelected()) {
            String field11Str = this.field11.getText();
            String field12Str = this.field12.getText();
            SBTFxDialog.Response buttonSelected = SBTFxDialog.showConfirmDialog(null,
                    "您确定【" + field11Str + "】替换为【"+field12Str+"】",
                    "【提示】");
            if (SBTFxDialog.Response.YES.equals(buttonSelected)) {
                SBTFxDialog.showConfirmDialog(null, "您选择checkBox1。", "【提示】");
            }
            return;
        }


        //文件校验
        String filePath = this.fileLabel.getText();
        if ("请选择文件......".equals(filePath) || null == filePath) {
            SBTFxDialog.showConfirmDialog(null, "您还没选择文件。", "【提示】");
            return;
        }
        if (!filePath.endsWith(".mdb")) {
            SBTFxDialog.showConfirmDialog(null, "请选择.mdb文件。", "【提示】");
            return;
        }
        String sql = "update yw set tm=qfywbf";
        int rs = DbTool.exeUpdateSql(filePath, sql);
        SBTFxDialog.showConfirmDialog(null, "共更新" + rs + "条记录。", "【恭喜你，执行成功】");
    }


    @FXML
    public void selectFileHandle(Event event) {
//        String filePath = this.fileLabel.getText();
//        if (null != filePath && filePath.endsWith(".mdb")) {
//            this.fileChooser.setInitialDirectory(new File(filePath).getParentFile());
//            this.fileChooser.setInitialFileName(filePath);
//        }
        File file = this.fileChooser.showOpenDialog(null);
        if (null != file) {
            this.fileLabel.setText(file.getPath());
        }
    }

}
